package mysql

import (
	"gorm.io/gorm"
	"home-manager/homerpc/homerpc"
)

type Home struct {
	gorm.Model
	HomeName    string `gorm:"type:varchar(30)"`
	HomeAddress string `gorm:"type:varchar(30)"`
}

func (h *Home) HomeShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(h).Error
}

func HomeList(db *gorm.DB) ([]*homerpc.HomeList, error) {
	var list []*homerpc.HomeList
	err2 := db.Debug().Model(&Home{}).Select(
		"id as home_id",
		"home_name",
		"home_address",
	).Find(&list).Error

	return list, err2
}
